<!--
 * @Author: your name
 * @Date: 2022-01-19 16:31:17
 * @LastEditTime: 2022-01-19 16:35:54
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \算法测试\day0906\剑指30.min栈实现.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var MinStack = function () {
            this.nums = [];
            this.mins = [];
        };

        /** 
         * @param {number} x
         * @return {void}
         */
        MinStack.prototype.push = function (x) {
            this.nums.push(x);
            if (this.mins.length === 0 || this.mins[this.mins.length - 1] >= x) {
                this.mins.push(x);
            }
        };

        /**
         * @return {void}
         */
        MinStack.prototype.pop = function () {
            if (this.nums[this.nums.length - 1] === this.mins[this.mins.length - 1]) {
                this.mins.pop();
            }
            this.nums.pop();
        };

        /**
         * @return {number}
         */
        MinStack.prototype.top = function () {
            return this.nums[this.nums.length - 1];
        };

        /**
         * @return {number}
         */
        MinStack.prototype.min = function () {
            return this.mins[this.mins.length - 1];
        };

        var obj = new MinStack()
        console.log(obj);
        obj.push(10);
        obj.pop();
        var param_3 = obj.top();
        console.log(param_3);
        var param_4 = obj.min();
        console.log(param_4);
    </script>
</body>

</html>